import { formatSongIds } from '@/utils/format';
import service from './request';

export function getRanking(id: number) {
  return service({
    url: '/playlist/detail',
    params: {
      id,
    },
  });
}

export function getSongDetail(ids: number | number[]) {
  return service({
    url: '/song/detail',
    params: {
      ids: Array.isArray(ids) ? ids.join(',') : ids,
    },
  });
}

export async function getAllSongs(id: number) {
  const res: any = await getRanking(id);
  const ids = formatSongIds(res.playlist.trackIds);
  const allSongs = await getSongDetail(ids);
  return allSongs;
}
export function getAlbum(id: number, limit: number = 20) {
  return service({
    url: '/album',
    params: {
      id,
      limit,
    },
  });
}
export async function getAllAlbum(id: number) {
  const res: any = await getAlbum(id);
  return res;
}
